import const
import uicls
import uiconst
import blue
import uthread

class AnimSpriteCore(uicls.IconCore):
    __guid__ = 'uicls.AnimSpriteCore'

    def Startup(self, x, y, dx, dy, steps):
        self.step = 0
        self.play = 0
        self.playing = 0
        self.x = x
        self.dx = dx
        self.steps = steps
        self.rectLeft = x
        self.rectTop = y



    def Loop(self):
        while (self and (not self.destroyed)):
            self.playing = 1
            self.rectLeft = (self.x + (self.step * self.dx))
            self.step += 1
            self.state = uiconst.UI_NORMAL
            if (self.step >= self.steps):
                self.step = 0
            blue.pyos.synchro.Sleep(125)
            if self.destroyed:
                return 
            if ((not self.play) and (self.step == 1)):
                self.state = uiconst.UI_HIDDEN
                break

        if not self.destroyed:
            self.playing = 0



    def Stop(self):
        self.play = 0



    def Play(self):
        self.play = 1
        if not self.playing:
            self.playing = 1
            uthread.new(self.Loop)




